<!--  -->
<template>
  <div>
    <el-input
      type="textarea"
      :autosize="{ minRows: 4, maxRows: 10 }"
      placeholder="留下你对公司的意见或建议吧"
      v-model="comment"
      style="width: 60%; margin: 18px 20% 0 20%"
    ></el-input>
    <div>
      <el-row :gutter="20">
        <el-col :span="12" :offset="5">
          <el-input
            placeholder="可以选择留下自己的昵称"
            v-model="nickname"
          ></el-input>
        </el-col>
        <el-col :span="7">
          <el-button
            @click="submit"
            type="primary"
            v-loading="loading"
            style="margin-bottom: 18px"
            >留言</el-button
          >
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  name: "AddLiuYan",
  data() {
    return {
      comment: "",
      nickname: "",
      loading: false,
    };
  },
  // inject: ["reload"], //封装reload，用于刷新页面
  methods: {
    submit() {
      this.loading = true;
      if (this.comment == "") {
        this.$message.error("你好像没有留言内容哦");
        this.loading = false;
        return;
      }
      var params = {
        nickname: this.nickname,
        comment: this.comment,
      };
      this.$request.post("/leave-word/insert", params).then((res) => {
        if (res.data.obj) {
          this.$message.success("留言成功");
          this.loading = false;
          this.comment = "";
          this.nickname = "";
          this.$emit("reload"); //子组件触发父组件的函数（父子传值问题）
        } else {
          this.$message.error("留言失败");
          this.loading = false;
        }
      });
    },
  },
};
</script>
<style>
</style>
